home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CICA Windows Explosion!
/
The CICA Windows Explosion! - Disc 2.iso
/
programr
/
ole2book.zip
/
CHAP11.ZIP
/
CHAP11
/
POLYLINE
/
IVIEWOBJ.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-22
|
10KB
|
358 lines
/*
* IVIEWOBJ.CPP
* Polyline Component Object Chapter 11
*
* Copyright (c)1993 Microsoft Corporation, All Rights Reserved
*
* Kraig Brockschmidt, Software Design Engineer
* Microsoft Systems Developer Relations
*
* Internet : kraigb@microsoft.com
* Compuserve: >INTERNET:kraigb@microsoft.com
*/
#include "polyline.h"
/*
* CImpIViewObject::CImpIViewObject
* CImpIViewObject::~CImpIViewObject
*
* Parameters (Constructor):
* pObj LPCPolyline of the object we're in.
* punkOuter LPUNKNOWN to which we delegate.
*/
CImpIViewObject::CImpIViewObject(LPCPolyline pObj, LPUNKNOWN punkOuter)
{
m_cRef=0;
m_pObj=pObj;
m_punkOuter=punkOuter;
return;
}
CImpIViewObject::~CImpIViewObject(void)
{
return;
}
/*
* CImpIViewObject::QueryInterface
* CImpIViewObject::AddRef
* CImpIViewObject::Release
*
* Purpose:
* IUnknown members for CImpIViewObject object.
*/
STDMETHODIMP CImpIViewObject::QueryInterface(REFIID riid, LPVOID FAR *ppv)
{
return m_punkOuter->QueryInterface(riid, ppv);
}
STDMETHODIMP_(ULONG) CImpIViewObject::AddRef(void)
{
++m_cRef;
return m_punkOuter->AddRef();
}
STDMETHODIMP_(ULONG) CImpIViewObject::Release(void)
{
--m_cRef;
return m_punkOuter->Release();
}
/*
* CImpIViewObject::Draw
*
* Purpose:
* Draws the object on the given hDC specifically for the requested
* aspect, device, and within the appropriate bounds.
*
* Parameters:
* dwAspect DWORD aspect to draw.
* lindex LONG index of the piece to draw.
* pvAspect LPVOID for extra information, always NULL.
* ptd DVTARGETDEVICE FAR * containing device information.
* hICDev HDC containing the IC for the device.
* hDC HDC on which to draw.
* pRectBounds LPRECTL describing the rectangle in which to draw.
* pRectWBounds LPRECTL describing the placement rectangle if part
* of what you draw is another metafile.
* pfnContinue Function to call periodically during long repaints.
* dwContinue DWORD extra information to pass to the pfnContinue.
*
* Return Value:
* HRESULT NOERROR on success, error code otherwise.
*/
STDMETHODIMP CImpIViewObject::Draw(DWORD dwAspect, LONG lindex
, void FAR * pvAspect, DVTARGETDEVICE FAR * ptd, HDC hICDev
, HDC hDC, const LPRECTL pRectBounds, const LPRECTL pRectWBounds
, BOOL (CALLBACK * pfnContinue) (DWORD), DWORD dwContinue)
{
RECT rc;
POLYLINEDATA pl;
LPPOLYLINEDATA ppl=&m_pObj->m_pl;
RECTFROMRECTL(rc, *pRectBounds);
//Delegate iconic and printed representations.
if (!((DVASPECT_CONTENT | DVASPECT_THUMBNAIL) & dwAspect))
{
return m_pObj->m_pDefIViewObject->Draw(dwAspect, lindex
, pvAspect, ptd, hICDev, hDC, pRectBounds, pRectWBounds
, pfnContinue, dwContinue);
}
/*
* If we're asked to draw a frozen aspect, use the data from
* a copy we made in IViewObject::Freeze. Otherwise use the
* current data.
*/
if (dwAspect & m_pObj->m_dwFrozenAspects)
{
//Point to the data to actually use.
if (DVASPECT_CONTENT==dwAspect)
ppl=&m_pObj->m_plContent;
else
ppl=&m_pObj->m_plThumbnail;
}
//Make a copy so we can modify it (and not worry about threads)
_fmemcpy(&pl, ppl, CBPOLYLINEDATA);
/*
* If we're going to a printer, check if it's color capable.
* if not, then use black on white for this figure.
*/
if (NULL!=hICDev)
{
if (GetDeviceCaps(hICDev, NUMCOLORS) <= 2)
{
pl.rgbBackground=RGB(255, 255, 255);
pl.rgbLine=RGB(0, 0, 0);
}
}
m_pObj->Draw(hDC, FALSE, TRUE, &rc, &pl);
return NOERROR;
}
/*
* CImpIViewObject::GetColorSet
*
* Purpose:
*
* Parameters:
* dwAspect DWORD aspect of interest.
* lindex LONG piece of interest.
* pvAspect LPVOID containing extra information, always NULL.
* ptd DVTARGETDEVICE FAR * containing device information.
* hICDev HDC containing the IC for the device.
* ppColorSet LPLOGPALETTE FAR * into which to return the pointer
* to the palette in this color set.
*
* Return Value:
* HRESULT NOERROR on success, S_FALSE if not supported.
*/
STDMETHODIMP CImpIViewObject::GetColorSet(DWORD dwDrawAspect, LONG lindex
, LPVOID pvAspect, DVTARGETDEVICE FAR * ptd
, HDC hICDev, LPLOGPALETTE FAR * ppColorSet)
{
return ResultFromScode(S_FALSE);
}
/*
* CImpIViewObject::Freeze
*
* Purpose:
* Freezes the view of a particular aspect such that data changes do
* no affect the view.
*
* Parameters:
* dwAspect DWORD aspect to freeze.
* lindex LONG piece index under consideration.
* pvAspect LPVOID for further information, always NULL.
* pdwFreeze LPDWORD in which to return the key.
*
* Return Value:
* HRESULT NOERROR on success, error code otherwise.
*/
STDMETHODIMP CImpIViewObject::Freeze(DWORD dwAspect, LONG lindex
, LPVOID pvAspect, LPDWORD pdwFreeze)
{
//Delegate anything for ICON or DOCPRINT aspects
if (!((DVASPECT_CONTENT | DVASPECT_THUMBNAIL) & dwAspect))
{
return m_pObj->m_pDefIViewObject->Freeze(dwAspect, lindex
, pvAspect, pdwFreeze);
}
if (dwAspect & m_pObj->m_dwFrozenAspects)
{
*pdwFreeze=dwAspect + FREEZE_KEY_OFFSET;
return ResultFromScode(VIEW_S_ALREADY_FROZEN);
}
m_pObj->m_dwFrozenAspects |= dwAspect;
/*
* For whatever aspects become frozen, make a copy of the data.
* Later when drawing, if such a frozen aspect is requested, we'll
* draw from this data rather than from our current data.
*/
if (DVASPECT_CONTENT & dwAspect)
_fmemcpy(&m_pObj->m_plContent, &m_pObj->m_pl, CBPOLYLINEDATA);
if (DVASPECT_THUMBNAIL & dwAspect)
_fmemcpy(&m_pObj->m_plThumbnail, &m_pObj->m_pl, CBPOLYLINEDATA);
if (NULL!=pdwFreeze)
*pdwFreeze=dwAspect + FREEZE_KEY_OFFSET;
return NOERROR;
}
/*
* CImpIViewObject::Unfreeze
*
* Purpose:
* Thaws an aspect frozen in ::Freeze. We expect that a container
* will redraw us after freezing if necessary, so we don't send
* any sort of notification here.
*
* Parameters:
* dwFreeze DWORD key returned from ::Freeze.
*
* Return Value:
* HRESULT NOERROR on success, error code otherwise.
*/
STDMETHODIMP CImpIViewObject::Unfreeze(DWORD dwFreeze)
{
DWORD dwAspect=dwFreeze - FREEZE_KEY_OFFSET;
//Delegate anything for ICON or DOCPRINT aspects
if (!((DVASPECT_CONTENT | DVASPECT_THUMBNAIL) & dwAspect))
m_pObj->m_pDefIViewObject->Unfreeze(dwFreeze);
//The aspect to unfreeze is in the key.
m_pObj->m_dwFrozenAspects &= ~(dwAspect);
/*
* Since we always kept our current data up to date, we don't
* have to do anything thing here like requesting data again.
* Because we removed dwAspect from m_dwFrozenAspects, Draw
* will again use the current data.
*/
return NOERROR;
}
/*
* CImpIViewObject::SetAdvise
*
* Purpose:
* Provides an advise sink to the view object enabling notifications
* for a specific aspect.
*
* Parameters:
* dwAspects DWORD describing the aspects of interest.
* dwAdvf DWORD containing advise flags.
* pIAdviseSink LPADVISESINK to notify.
*
* Return Value:
* HRESULT NOERROR on success, error code otherwise.
*/
STDMETHODIMP CImpIViewObject::SetAdvise(DWORD dwAspects, DWORD dwAdvf
, LPADVISESINK pIAdviseSink)
{
//Pass anything with DVASPECT_ICON or _DOCPRINT to the handler.
if (!((DVASPECT_CONTENT | DVASPECT_THUMBNAIL) & dwAspects))
m_pObj->m_pDefIViewObject->SetAdvise(dwAspects, dwAdvf, pIAdviseSink);
//We continue because dwAspects may have more than one in it.
if (NULL!=m_pObj->m_pIAdviseSink)
m_pObj->m_pIAdviseSink->Release();
m_pObj->m_dwAdviseAspects=dwAspects;
m_pObj->m_dwAdviseFlags=dwAdvf;
if (NULL!=pIAdviseSink)
{
m_pObj->m_pIAdviseSink=pIAdviseSink;
m_pObj->m_pIAdviseSink->AddRef();
}
return NOERROR;
}
/*
* CImpIViewObject::GetAdvise
*
* Purpose:
* Returns the last known IAdviseSink seen by ::SetAdvise.
*
* Parameters:
* pdwAspects LPDWORD in which to store the last requested aspects.
* pdwAdvf LPDWORD in which to store the last requested flags.
* ppIAdvSink LPADVISESINK FAR * in which to store the IAdviseSink.
*
* Return Value:
* HRESULT NOERROR on success, error code otherwise.
*/
STDMETHODIMP CImpIViewObject::GetAdvise(LPDWORD pdwAspects
, LPDWORD pdwAdvf, LPADVISESINK FAR* ppAdvSink)
{
if (NULL==ppAdvSink)
return ResultFromScode(E_INVALIDARG);
else
{
*ppAdvSink=m_pObj->m_pIAdviseSink;
m_pObj->m_pIAdviseSink->AddRef();
}
if (NULL!=pdwAspects)
*pdwAspects=m_pObj->m_dwAdviseAspects;
if (NULL!=pdwAdvf)
*pdwAdvf=m_pObj->m_dwAdviseFlags;
return NOERROR;
}